﻿package tbo.view 
{
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.KeyboardEvent;
	import flash.events.MouseEvent;
	import tbo.components.buttons.EndBtn;
	import tbo.game.BattleManager;
	import tbo.components.ActorQuickView;
	import tbo.events.TBOActorEvent;
	import tbo.components.buttons.MoveBtn;
	import tbo.components.buttons.AttackBtn;
	/**
	 * ...
	 * @author ...
	 */
	public class BattleView extends Sprite
	{
		protected var _battleManager:BattleManager;
		protected var _selectedActor:ActorQuickView;
		protected var btnMove:MoveBtn;
		protected var btnEnd:EndBtn;
		protected var btnAtk:AttackBtn;
		
		public function BattleView() 
		{
			this.addEventListener(Event.ADDED_TO_STAGE, init);
		}
		
		public function init(e:Event):void {
			
			_battleManager = new BattleManager();
			stage.addEventListener(KeyboardEvent.KEY_DOWN, translateInput);
			this.addChild(_battleManager._tacticalStage);
			
			btnMove = new MoveBtn();
			btnMove.x = 400;
			btnMove.y = 200;
			btnMove.addEventListener(MouseEvent.CLICK, onMoveClick);
			this.addChild(btnMove);
			
			btnEnd = new EndBtn;
			btnEnd.x = 400;
			btnEnd.y = 230;
			btnEnd.addEventListener(MouseEvent.CLICK, onEndClick);
			this.addChild(btnEnd);
			
			_selectedActor = new ActorQuickView();
			_selectedActor.x = 400;
			this.addChild(_selectedActor);
			_battleManager.addEventListener(TBOActorEvent.ACTOR_CLICKED, showActorInfo);
		}
		
		protected function showActorInfo(e:TBOActorEvent):void {
			_selectedActor.setActor(e.actor);
		}
		
		protected function onAtkClick(e:MouseEvent):void {
			_battleManager.setState("attack");
		}
		
		protected function onMoveClick(e:MouseEvent):void {
			_battleManager.setState("move");
		}
		
		protected function onEndClick(e:MouseEvent):void {
			_battleManager.executeTurn();
		}
		
		protected function translateInput(e:KeyboardEvent):void {
			_battleManager.executeTurn();
		}
	}
	
}